import {
	baseUrl
} from "./config.js";


export function curl(url, data) {
	// myapi.getcategory
	return new Promise(function(reslove, reject) {

	
	var	headers = {
			"Content-Type": "application/x-www-form-urlencoded",
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Method":"POST,GET"
		}
		
	
		uni.request({
			url: `${baseUrl}`+url,
			// url:"/dpc"+url,
			method: 'POST',
			data: data,
			header: headers,
			success: res => {
				// console.log('*****',res.data);
				
				
				//需要登陆时 就跳转
				if (res.data.code == '401') {
					uni.setStorageSync('token','');
					uni.setStorageSync('user','');
					uni.reLaunch({
					
						url: '/pages/login/login'
					})
					return false;
				}
				reslove(res.data);
			},
			fail: (res) => {
				console.log(res)
			},
		});
	})
}
